<template>
  <div>
    <r-treenode
      v-for="item in items"
      :key="item[itemkey]"
      :rkey="item[itemkey]"
      :text="item[itemtext]"
      :items="item.children"
      :isdir="item.isdir"
    >
      <template v-slot:prepend>
        <slot name="prepend"></slot>
     </template> 
    </r-treenode>
  </div>
</template>

<script>
import RTreenode from "./RTreenode";

export default {
  name: "RTree",
  data() {
    return {
      // 存储节点状态数据，例如激活等
      store: {
        active: {}, // 使用节点唯一的值作为键值
        show: {},
      },
      change: false, // 用于表示当前所有子节点发生变化
    };
  },
  props: {
    items: {
      type: Array,
    },
    itemkey: { type: String },
    itemtext: { type: String },
  },
  components: { RTreenode },
  methods: {
    toggleShow(key) {
      this.store.show[key] = !this.store.show[key];
      this.change = !this.change;
    },
    setData(status, key, val) {
        if(this.store[status] == null) {
          this.store[status] = {}
        }
        this.store[status][key] = val
        this.change = !this.change;
    },
    getData(status ,key) {
        if(this.store[status] != null) {
          return this.store.[status][key]
        }
        return null
    }
  },

  created() {
    this.isTree = true;
  },
};
</script>
<style scoped></style>
